﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;

namespace KaoShiClent
{
    public partial class ClientWin : Form
    {
        public ClientWin()
        {
            InitializeComponent();
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            IPAddress ip = IPAddress.Parse("127.0.0.1");
            IPEndPoint ipPoint = new IPEndPoint(ip, 8989);

            Socket sSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sSocket.Connect(ipPoint);

            string strSend = "客户  " + txtName.Text.Trim() + " Send:" + DateTime.Now;
            //字符串转换成字节发送
            var sendRes = sSocket.Send(Encoding.UTF8.GetBytes(strSend));
            if (sendRes > 0)
            {
                byte[] byts = new byte[512000];//4MB
                var receiveRes = sSocket.Receive(byts, byts.Length, SocketFlags.None);
                //字节转换成字符串
                string strReceive = Encoding.UTF8.GetString(byts);
                MessageBox.Show(strReceive);
            }

        }
    }
}
